package com.bwie.controller;

import com.bwie.pojo.Result;
import com.bwie.pojo.User;
import com.bwie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService ;

    /**
     * 跳登录页面
     * @return
     */
    @RequestMapping("toLogin")
    public String toLogin(){
        return "/user/login";
    }

    /**
     * 获取验证码接口
     * @param phone
     * @return
     */
    @PostMapping("sendSmsCode")
    @ResponseBody
    public Result sendSmsCode(String phone){
        userService.sendSmsCode(phone);
        return Result.success("发送成功");
    }

    /**
     * 登录
     * @param user
     * @return
     */
    @PostMapping("doSmsLogin")
    @ResponseBody
    public Result doSmsLogin(@RequestBody User user){
        userService.doSmsLogin(user);
        return Result.success("登录成功");
    }

}
